package com.ms.dsq_english.wall

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.ms.dsq_english.R
import com.ms.dsq_english.adapter.RVAdapterAreaCurrent
import com.ms.dsq_english.model.StoreBean
import com.ms.dsq_english.model.StoreBean.DataBean.NewShopBean.ShopDetailsBean
import com.ms.dsq_english.utils.LogUtils
import com.ms.dsq_english.http.HttpManager
import com.ms.dsq_english.utils.MapUtilsParamNull
import com.ms.dsq_english.utils.ResultCheckUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.frag_store.*
import lecho.lib.hellocharts.model.*
import java.math.BigDecimal
import java.util.*

/**
 * @Description:
 * @Author: zheng
 */
class StoreFragment : Fragment()
{
    private var list= ArrayList<StoreBean.DataBean.SalesRegionBean>()
    private lateinit var mContext: Context



    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
    {
        mContext = context!!

        return inflater.inflate(R.layout.frag_store, container, false)
    }

    override fun onResume() {
        super.onResume()
        Glide.with(mContext).load(R.drawable.img_store_a).into(store_img)
        store()
        yellow.setOnClickListener {
            for (i in list.indices) {
                if (list[i].pname == "山东省") {
                    sales_num.setText("山东省门店数：")
                    sales_num1.text =list[i].nums
                }
            }
        }
        green.setOnClickListener {
            for (i in list.indices) {
                if (list[i].pname == "河南省") {
                    sales_num.setText("河南省门店数：")
                    sales_num1.text =list[i].nums
                }
            }
        }
        bule.setOnClickListener {
            for (i in list.indices) {
                if (list[i].pname == "安徽省") {
                    sales_num.setText("安徽省门店数：")
                    sales_num1.text =list[i].nums
                }
            }
        }
        zi.setOnClickListener {
            for (i in list.indices) {
                if (list[i].pname == "江苏省") {
                    sales_num.setText("江苏省门店数：")
                    sales_num1.text =list[i].nums
                }
            }
        }
        gans2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "甘肃省") {
                    sales_num.text = "甘肃省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        shanx2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "陕西省") {
                    sales_num.text = "陕西省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sanx2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "山西省") {
                    sales_num.text = "山西省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        ningx2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "宁夏回族自治区") {
                    sales_num.text = "宁夏回族自治区门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        guangd2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "广东省") {
                    sales_num.text = "广东省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng1.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "江西省") {
                    sales_num.text = "江西省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng2.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "浙江省") {
                    sales_num.text = "浙江省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng3.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "福建省") {
                    sales_num.text = "福建省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng4.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "湖北省") {
                    sales_num.text = "湖北省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng5.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "四川省") {
                    sales_num.text = "四川省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng6.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "贵州省") {
                    sales_num.text = "贵州省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng7.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "湖南省") {
                    sales_num.text = "湖南省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng8.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "海南省") {
                    sales_num.text = "海南省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng10.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "重庆") {
                    sales_num.text = "重庆门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng11.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "天津") {
                    sales_num.text = "天津门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng12.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "内蒙古自治区") {
                    sales_num.text = "内蒙古自治区门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng13.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "黑龙江省") {
                    sales_num.text = "黑龙江省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng14.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "吉林省") {
                    sales_num.text = "吉林省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng15.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "辽宁省") {
                    sales_num.text = "辽宁省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng16.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "河北省") {
                    sales_num.text = "河北省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng17.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "北京") {
                    sales_num.text = "北京门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }

        sheng18.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "青海省") {
                    sales_num.text = "青海省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }

        sheng19.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "广西壮族自治区") {
                    sales_num.text = "广西壮族自治区门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }

        sheng20.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "云南省") {
                    sales_num.text = "云南省门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng21.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "新疆维吾尔自治区") {
                    sales_num.text = "新疆维吾尔自治区门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
        sheng22.setOnClickListener {
            var i = 0
            while (i < list.size) {
                if (list[i].pname == "西藏自治区") {
                    sales_num.text = "西藏自治区门店数："
                    sales_num1.text = list[i].nums
                }
                i++
            }
        }
    }


    public fun refresh(){
        store()
    }

    //门店覆盖区域
    //新增门店
    //覆盖情况
    @SuppressLint("CheckResult")
    private fun store()
    {

        val params: HashMap<String, String> = MapUtilsParamNull()
                .getBaseMap(mContext)

        HttpManager.getRetrofitInterface()
                .getStore(params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ result: StoreBean ->
                    if (result.code == 10000)
                    { //门店覆盖区域
                        shop_time.text = "截止时间：" + result.data.last_time
                        //新增门店
                        initRecyclerViewCurrent(result.data.new_shop.shop_details)
                        shop_count.text = result.data.new_shop.shop_count
                        //覆盖情况
                        val amount = result.data.all_shop_count
                        if (amount.length == 6)
                        {
                            num1.text = amount[0].toString()
                            num2.text = amount[1].toString()
                            num3.text = amount[2].toString()
                            num4.text = amount[3].toString()
                            num5.text = amount[4].toString()
                            num6.text = amount[5].toString()
                        }
                        if (amount.length == 5)
                        {
                            num1.text = "0"
                            num2.text = amount[0].toString()
                            num3.text = amount[1].toString()
                            num4.text = amount[2].toString()
                            num5.text = amount[3].toString()
                            num6.text = amount[4].toString()
                        }
                        if (amount.length == 4)
                        {
                            num1.text = "0"
                            num2.text = "0"
                            num3.text = amount[0].toString()
                            num4.text = amount[1].toString()
                            num5.text = amount[2].toString()
                            num6.text = amount[3].toString()
                        }
                        if (amount.length == 3)
                        {
                            num1.text = "0"
                            num2.text = "0"
                            num3.text = "0"
                            num4.text = amount[0].toString()
                            num5.text = amount[1].toString()
                            num6.text = amount[2].toString()
                        }
                        if (amount.length == 2)
                        {
                            num1.text = "0"
                            num2.text = "0"
                            num3.text = "0"
                            num4.text = "0"
                            num5.text = amount[0].toString()
                            num6.text = amount[1].toString()
                        }
                        if (amount.length == 1)
                        {
                            num1.text = "0"
                            num2.text = "0"
                            num3.text = "0"
                            num4.text = "0"
                            num5.text = "0"
                            num6.text = amount[0].toString()
                        }

                        //店单产划分
                        val shopUnit = result.data.shop_unit

                        frg_sc_tv1.text = shopUnit[0].title
                        frg_shop_hpv1.progress = BigDecimal(shopUnit[0].month_count).toInt()
                        frg_shop_hpv1.runProgressAnim(2000)
                        frg_shop_tv1.text=shopUnit[0].month_count+"%"
                        frg_shop_hpv2.progress = BigDecimal(shopUnit[0].pre_count).toInt()
                        frg_shop_hpv2.runProgressAnim(2000)
                        frg_shop_tv2.text=shopUnit[0].pre_count+"%"

                        frg_sc_tv2.text = shopUnit[1].title
                        frg_shop_hpv3.progress = BigDecimal(shopUnit[1].month_count).toInt()
                        frg_shop_hpv3.runProgressAnim(2000)
                        frg_shop_tv3.text=shopUnit[1].month_count+"%"
                        frg_shop_hpv4.progress = BigDecimal(shopUnit[1].pre_count).toInt()
                        frg_shop_hpv4.runProgressAnim(2000)
                        frg_shop_tv4.text=shopUnit[1].pre_count+"%"

                        frg_sc_tv3.text = shopUnit[2].title
                        frg_shop_hpv5.progress = BigDecimal(shopUnit[2].month_count).toInt()
                        frg_shop_hpv5.runProgressAnim(2000)
                        frg_shop_tv5.text=shopUnit[2].month_count+"%"
                        frg_shop_hpv6.progress = BigDecimal(shopUnit[2].pre_count).toInt()
                        frg_shop_hpv6.runProgressAnim(2000)
                        frg_shop_tv6.text=shopUnit[2].pre_count+"%"

                        frg_sc_tv4.text = shopUnit[3].title
                        frg_shop_hpv7.progress = BigDecimal(shopUnit[3].month_count).toInt()
                        frg_shop_hpv7.runProgressAnim(2000)
                        frg_shop_tv7.text=shopUnit[3].month_count+"%"
                        frg_shop_hpv8.progress = BigDecimal(shopUnit[3].pre_count).toInt()
                        frg_shop_hpv8.runProgressAnim(2000)
                        frg_shop_tv8.text=shopUnit[3].pre_count+"%"

                        frg_sc_tv5.text = shopUnit[4].title
                        frg_shop_hpv9.progress = BigDecimal(shopUnit[4].month_count).toInt()
                        frg_shop_hpv9.runProgressAnim(2000)
                        frg_shop_tv9.text=shopUnit[4].month_count+"%"
                        frg_shop_hpv10.progress = BigDecimal(shopUnit[4].pre_count).toInt()
                        frg_shop_hpv10.runProgressAnim(2000)
                        frg_shop_tv10.text=shopUnit[4].pre_count+"%"

                        //门店数据
                        val shopData = result.data.shop_data

                        initComboLineColumnChartView(shopData)

                        //店均单产
                        store_dc.text = result.data.shop_average

                        //本月数据
                        store_by.text = result.data.month_cover.login_count
                        store_by1.text = result.data.month_cover.active_count
                        store_c1.progress =result.data.month_cover.login_rate.toInt()
                        store_c2.progress =result.data.month_cover.pre_login_rate.toInt()
                        store_c3.progress =result.data.month_cover.active_rate.toInt()
                        store_c4.progress =result.data.month_cover.pre_active_rate.toInt()

                        //地图
                        list.clear()
                        list.addAll(result.data.sales_region)

                        //门店排行
                        store_md.text =result.data.order_rinking.get(0).address+result.data.order_rinking.get(0).shop_name
                        store_md1.text =result.data.order_rinking.get(0).amounts+"千元"
                        store_mdd.text =result.data.order_rinking.get(1).address+result.data.order_rinking.get(1).shop_name
                        store_mdd1.text =result.data.order_rinking.get(1).amounts+"千元"
                        store_mddd.text =result.data.order_rinking.get(2).address+result.data.order_rinking.get(2).shop_name
                        store_mddd1.text =result.data.order_rinking.get(2).amounts+"千元"
                        store_mdddd.text =result.data.order_rinking.get(3).address+result.data.order_rinking.get(3).shop_name
                        store_mdddd1.text =result.data.order_rinking.get(3).amounts+"千元"
                        store_mddddd.text =result.data.order_rinking.get(4).address+result.data.order_rinking.get(4).shop_name
                        store_mddddd1.text =result.data.order_rinking.get(4).amounts+"千元"



                    }
                    else
                    {
                        ResultCheckUtils().checkResult(mContext, result.code, result.msg)
                    }
                }
                ) { e: Throwable -> LogUtils.showLog(HttpManager.TAG, e.message) }
    }

    private fun initRecyclerViewCurrent(list: ArrayList<ShopDetailsBean>)
    {
        store_rec.layoutManager = LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false)
        store_rec.adapter = RVAdapterAreaCurrent(mContext, list)
        store_rec.start()
    }

    //X轴展示内容
    private fun getXValues(list: ArrayList<StoreBean.DataBean.ShopDataBean>): List<AxisValue>
    {

        val listAxisXValues = ArrayList<AxisValue>()

        listAxisXValues.add(AxisValue(0.toFloat()).setLabel(list[0].months ))
        listAxisXValues.add(AxisValue(1.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(2.toFloat()).setLabel(list[1].months ))
        listAxisXValues.add(AxisValue(3.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(4.toFloat()).setLabel(list[2].months ))
        listAxisXValues.add(AxisValue(5.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(6.toFloat()).setLabel(list[3].months ))
        listAxisXValues.add(AxisValue(7.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(8.toFloat()).setLabel(list[4].months ))
        listAxisXValues.add(AxisValue(9.toFloat()).setLabel(""))
        listAxisXValues.add(AxisValue(10.toFloat()).setLabel(list[5].months ))
//        listAxisXValues.add(AxisValue(11.toFloat()).setLabel(""))

//
//        //设置X轴显示
//        for (i in list.indices)
//        {
//            if(i%2==0){
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }else{
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(list[i].months ))
//                listAxisXValues.add(AxisValue(i.toFloat()).setLabel(""))
//            }
//        }


        return listAxisXValues
    }

    //Y轴展示内容
    private fun getYValues(maxYValue: Float, isHarPer: Boolean): List<AxisValue>
    {
        val listAxisYValues = ArrayList<AxisValue>()
        var per = 10

        when
        {
            maxYValue > 0 && maxYValue <= 50 -> per = 5
            maxYValue > 50 && maxYValue <= 100 -> per = 10
            maxYValue > 100 && maxYValue <= 500 -> per = 50
            maxYValue > 500 && maxYValue <= 1000 -> per = 100
            maxYValue > 1000 && maxYValue <= 5000 -> per = 250
            maxYValue > 5000 && maxYValue <= 10000 -> per = 500
            maxYValue > 10000 -> per = 1000
        }

        //设置Y轴显示
        var i = 0
        while (i <= maxYValue)
        {
            i += if (isHarPer && maxYValue > 0)
            {
                listAxisYValues.add(AxisValue(i.toFloat())
                        .setLabel("${formatPer(i * 100 / maxYValue)}%"))

                per
            }
            else
            {
                listAxisYValues.add(AxisValue(i.toFloat()).setLabel(i.toString()))

                per
            }
        }

        return listAxisYValues
    }

    private fun formatPer(per: Float): Int
    {
        return when
        {
            per > 0 && per <= 7 -> 5
            per > 7 && per <= 12 -> 10
            per > 12 && per <= 17 -> 15
            per > 17 && per <= 22 -> 20
            per > 22 && per <= 27 -> 25
            per > 27 && per <= 32 -> 30
            per > 32 && per <= 37 -> 35
            per > 37 && per <= 42 -> 40
            per > 42 && per <= 47 -> 45
            per > 47 && per <= 52 -> 50
            per > 52 && per <= 57 -> 55
            per > 57 && per <= 62 -> 60
            per > 62 && per <= 67 -> 65
            per > 67 && per <= 72 -> 70
            per > 72 && per <= 77 -> 75
            per > 77 && per <= 82 -> 80
            per > 82 && per <= 87 -> 85
            per > 87 && per <= 92 -> 90
            per > 92 && per <= 97 -> 95
            per > 97 && per <= 100 -> 100
            else -> 0
        }
    }

    //X轴
    private fun getXAxis(list: ArrayList<StoreBean.DataBean.ShopDataBean>): Axis
    {
        //X轴
        val axisX = Axis()
        //X轴标注
        //        axisX.setName("X轴");
        //设置字体颜色
        axisX.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisX.textSize = 6
        //是否有分割线
        axisX.setHasLines(false)
        //X坐标轴字体是否斜体
        axisX.setHasTiltedLabels(false)
        //填充X轴的坐标名称
        axisX.values = getXValues(list)
        //设置轴标签和名字的字体
        //        axisX.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        //        axisX.setMaxLabelChars(5);
        //设置是否自动生成轴对象，自动适应表格的范围
        axisX.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisX.isInside = false

        return axisX
    }

    //Y轴
    private fun getYAxis(maxYValue: Float, isHasPer: Boolean): Axis
    {
        //Y轴(不设置setValues会根据数据的大小自动设置Y轴上限)
        val axisY = Axis()
        //Y轴标注
        //        axisY.setName("Y轴");
        //设置字体颜色
        axisY.textColor = Color.parseColor("#748ebf")
        //设置字体大小
        axisY.textSize = 6
        //是否有分割线
        axisY.setHasLines(false)
        //Y坐标轴字体是否斜体
        axisY.setHasTiltedLabels(false)
        //填充Y轴的坐标名称
        axisY.values = getYValues(maxYValue, isHasPer)
        //设置轴标签和名字的字体
        //        axisY.setTypeface(Typeface typeface);
        //设置轴标签可显示的最大字符个数，范围在0-32之间
        axisY.maxLabelChars = 10
        //设置是否自动生成轴对象，自动适应表格的范围
        axisY.isAutoGenerated = false
        //设置是否将轴坐标的值显示在图表内侧
        axisY.isInside = false

        return axisY
    }

    //添加线
    private fun addLine(list: ArrayList<StoreBean.DataBean.ShopDataBean>, linePer: Float): Line
    {
        val listPointValue = ArrayList<PointValue>()

//        //设置图表数据点显示
//        for (i in list.indices)
//        {
//            listPointValue.add(PointValue(i.toFloat(), list[i].active_rate.toInt() * linePer)
//                    .setLabel(""))
////                    .setLabel("${list[i].active_rate.toInt()}%"))
//        }
        listPointValue.add(PointValue(0.toFloat(), list[0].active_rate.toInt() * linePer)
                .setLabel(""))
        listPointValue.add(PointValue(2.toFloat(), list[1].active_rate.toInt() * linePer)
                .setLabel(""))
        listPointValue.add(PointValue(4.toFloat(), list[2].active_rate.toInt() * linePer)
                .setLabel(""))
        listPointValue.add(PointValue(6.toFloat(), list[3].active_rate.toInt() * linePer)
                .setLabel(""))
        listPointValue.add(PointValue(8.toFloat(), list[4].active_rate.toInt() * linePer)
                .setLabel(""))
        listPointValue.add(PointValue(10.toFloat(), list[5].active_rate.toInt() * linePer)
                .setLabel(""))


        //折线
        val line = Line(listPointValue)
        //是否用线显示 如果为false 则没有曲线只有点显示
        line.setHasLines(true)
        //折线颜色
        line.color = Color.parseColor("#FCBD83")
        //折线粗细
        line.strokeWidth = 1
        //是否有数据点
        line.setHasPoints(true)
        //数据点大小
        line.pointRadius = 1
        //数据点颜色
        line.pointColor = Color.parseColor("#FCBD83")
        //折线上每个数据点形状(CIRCLE SQUARE DIAMOND)
        line.shape = ValueShape.CIRCLE
        //是否平滑
        line.isCubic = true
        //是否填充曲线的面积
        line.isFilled = false
        //曲线的数据坐标是否加上备注
        line.setHasLabels(true)
        //点击数据坐标提示数据（设置line.setHasLabels(true);就无效）
        //      line.setHasLabelsOnlyForSelected(true);

        return line
    }

    //添加柱

    private fun addColumn(data: StoreBean.DataBean.ShopDataBean,isShow: Boolean,order_num:String,active_num:String): Column
    {
        var order_nums = ""
        var active_nums = ""
        if (isShow){
            order_nums=order_num
            active_nums=active_num
        }
        val listColumnValue = ArrayList<SubcolumnValue>()
        listColumnValue.add(SubcolumnValue(data.order_num.toFloat(),
                if (isShow) Color.parseColor("#00B67C")else
                    Color.parseColor("#00000000"))
                .setLabel(order_nums))

        listColumnValue.add(SubcolumnValue(data.active_num.toFloat(),
                if (isShow) Color.parseColor("#029BE8")else
                    Color.parseColor("#00000000"))
                .setLabel(active_nums))

        //柱
        val column = Column(listColumnValue)
        //柱的数据坐标是否加上备注
        column.setHasLabels(true)
        //点击数据坐标提示数据（设置column.setHasLabels(true);就无效）
//        column.setHasLabelsOnlyForSelected(true)

        return column
    }

    private fun initComboLineColumnChartView(list: ArrayList<StoreBean.DataBean.ShopDataBean>)
    {
        var maxYValue = 0f
        var cMaxYValue = 0f
        var lMaxYValue = 0f
        var setPer = 1f

        for (data in list)
        {
            if (data.order_num.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.order_num.toFloat()
            }

            if (data.active_num.toFloat() > cMaxYValue)
            {
                cMaxYValue = data.active_num.toFloat()
            }

            if (data.active_rate.toFloat() > lMaxYValue)
            {
                lMaxYValue = data.active_rate.toFloat()
            }
        }

        maxYValue = cMaxYValue
        setPer = cMaxYValue / lMaxYValue

        LogUtils.showLog("tables", "maxYValue=$maxYValue-cMaxYValue=$cMaxYValue-lMaxYValue=$lMaxYValue-setPer=$setPer")

        //设置线数据
        val listLine = ArrayList<Line>()
        listLine.add(addLine(list, setPer))

        val lineChartData = LineChartData()
        lineChartData.lines = listLine

        //设置柱状图数据
        val listColumn = ArrayList<Column>()
        for (i in list.indices)
        {
            if (i==list.size-1){
                listColumn.add(addColumn(list[i],true,"",""))
                listColumn.add(addColumn(list[i],false,list.get(i).active_num,""))
            }else{
                listColumn.add(addColumn(list[i],true,"",""))
                listColumn.add(addColumn(list[i],false,"",""))
            }

        }

        val columnChartData = ColumnChartData()
        columnChartData.columns = listColumn

        ////////////////
        //给图表设置数据
        val comboLineColumnChartData = ComboLineColumnChartData()
        comboLineColumnChartData.lineChartData = lineChartData
        comboLineColumnChartData.columnChartData = columnChartData

        //设置标签背景颜色
        comboLineColumnChartData.valueLabelBackgroundColor = resources.getColor(R.color.transparent)
        //设置是否自动绘制标签背景
        comboLineColumnChartData.isValueLabelBackgroundAuto = false
        //设置标签文字颜色，默认为白色
        comboLineColumnChartData.setValueLabelsTextColor(Color.parseColor("#748ebf"))
        //设置标签文字字号，默认为12sp
        comboLineColumnChartData.valueLabelTextSize = 6

        //X轴在底部
        comboLineColumnChartData.axisXBottom = getXAxis(list)
        //Y轴设置在左边
        comboLineColumnChartData.axisYLeft = getYAxis(maxYValue, false)
        //Y轴设置在右边
        comboLineColumnChartData.axisYRight = getYAxis(maxYValue, true)
        frg_trs_ccv_clccv_tra.comboLineColumnChartData = comboLineColumnChartData

        //设置图表是可以交互的（拖拽，缩放等效果的前提）
        frg_trs_ccv_clccv_tra.isInteractive = false

        when
        {
            maxYValue > 0 && maxYValue <= 25 -> maxYValue += 5
            maxYValue > 25 && maxYValue <= 50 -> maxYValue += 10
            maxYValue > 50 && maxYValue <= 100 -> maxYValue += 20
            maxYValue > 100 && maxYValue <= 250 -> maxYValue += 50
            maxYValue > 250 && maxYValue <= 500 -> maxYValue += 200
            maxYValue > 500 && maxYValue <= 1000 -> maxYValue += 200
            maxYValue > 1000 && maxYValue <= 5000 -> maxYValue += 1000
            maxYValue > 5000 && maxYValue <= 10000 -> maxYValue += 2000
            maxYValue > 10000 -> maxYValue += 3000
        }

        //设置坐标轴的范围(left-1,right+1可以使X轴坐标前后有空间)
        val viewport = Viewport(-1f, maxYValue, getXValues(list).size.toFloat(), 0f)

        frg_trs_ccv_clccv_tra.maximumViewport = viewport
        frg_trs_ccv_clccv_tra.currentViewport = viewport
    }
}